package org.com.system.user;

import java.util.List;

import org.com.system.util.model.Action;
import org.com.system.util.model.Page;
import org.com.system.util.utils.ModelUtils;
import org.com.system.util.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class UserAction extends Action<User>{

	private static final long serialVersionUID = 1L;
	
	@Autowired()
	@Qualifier("userServer")
	public UserService server;
	
	public void init(){
		
	}
	
	/**
	 * 注册用户
	 * @return
	 */
	public String register(){
		User user=(User)ModelUtils.copyFromMap(getValues(), User.class);
		user.setId(UUIDUtils.getUUID());
		server.save(user);
		return SUCCESS;
	}
	
	/**
	 * 用户登陆
	 * @return
	 */
	public String login(){
		User user=server.get(getValues(), User.class);
		getSession().put("user", user);
		return SUCCESS;
	}
	
	/**
	 * 用户退出
	 * @return
	 */
	public String logout(){
		getSession().remove("user");
		return SUCCESS;
	}
	
	/**
	 * 查询用户
	 * @return
	 */
	public String list(){
		List<User> users=server.list(getValues(), User.class);
		write(users);
		return SUCCESS;
	}
	
	public String pageList(){
		Page page=new Page();
		getValues().updateBean(page, User.class);
		List<User> users=server.list(User.class, page);
		write(users);
		return SUCCESS;
	}
	
	/**
	 * 更新用户
	 * @return
	 */
	public String update(){
		init();
		return SUCCESS;
	}
	
	/**
	 * 删除用户
	 * @return
	 */
	public String delete(){
		init();
		return SUCCESS;
	}
	
}
